package com.atguigu.mySmartCampus.Service.impl;

import com.atguigu.mySmartCampus.mapper.GradeMapper;
import com.atguigu.mySmartCampus.Service.GradeService;
import com.atguigu.mySmartCampus.entity.Grade;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
//+
//..@Transnal
//..@Transcational
@Transactional
//..public class GradeServiceImpl{
//..public class GradeServiceImpl extends GradeService implements ServiceImpl<GradeMapper,Grade>{
public class GradeServiceImpl extends ServiceImpl<GradeMapper, Grade> implements GradeService {
    //..... @Autowired
    //..... GradeMapper gradeMapper;

    public IPage<Grade> getGradeByOperator(Page<Grade> pageParam, String gradeName) {
        //..... Page page = grade.selectPage(page,gradeName);
        //..... return page;

        QueryWrapper qw = new QueryWrapper();
        //..if(StringUtils.isEmpty(gradeName)){
        if (!StringUtils.isEmpty(gradeName)) {
            qw.like("name", gradeName);
        }
        //+
        qw.orderByDesc("id");
        //..... baseMapper.selectPage(qw,grade);
        Page<Grade> page = baseMapper.selectPage(pageParam, qw);
        return page;
    }

    public List<Grade> getGrade() {

        //..... return gradeMapper.selectList(null);
        return baseMapper.selectList(null);
    }
}